package com.itheima.controller;

<<<<<<< HEAD
import com.itheima.pojo.Article;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.service.ArticleService;
import com.itheima.utils.JwtUtil;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
=======
import com.itheima.pojo.Result;
import com.itheima.utils.JwtUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
>>>>>>> 08ea7c3a718b4abad24581cc274164043dc145f5

import java.util.Map;


@RestController
@RequestMapping("/article")
<<<<<<< HEAD
@RequiredArgsConstructor
@Validated
public class ArticleController {
    private final ArticleService articleService;
//登录验证测试
//    @GetMapping("/list")
//    public Result<String> list(/**@RequestHeader(name = "Authorization") String token, HttpServletResponse response**/){
////        if (token == null){
////            return Result.error("令牌为空");
////        }
////        try {
////            Map<String, Object> map = JwtUtil.parseToken(token);
////            return Result.success("文章列表...");
////        }catch (Exception e){
////            //set 404
////            response.setStatus(401);
////            return Result.error("未登录");
////        }
//        //添加过滤器统一过滤
//        return Result.success("文章列表...");
//    }
    @PostMapping
    public Result<String> addArticle(@RequestBody @Validated(Article.add.class) Article article){
        articleService.addArticle(article);
        return Result.success();

    }
    @GetMapping
    public Result<PageBean<Article>> pageQueryArticle(@RequestParam Integer pageNum
            ,@RequestParam Integer pageSize
            ,@RequestParam(required = false) Integer categoryId
            ,@RequestParam(required = false) String state){
        PageBean<Article> pb = articleService.pageQueryArticle(pageNum,pageSize,categoryId,state);
        return Result.success(pb);

    }
    @GetMapping("/detail")
    public Result<Article> articleDetailById(@RequestParam Integer id){
        Article article = articleService.articleDetailById(id);
        return Result.success(article);

    }
    @PutMapping
    public Result<String> updateArticle(@RequestBody Article article){
        articleService.updateArticle(article);
        return Result.success();

    }
    @DeleteMapping
    public Result<String> deleteArticleById(@RequestParam Integer id){
        articleService.deleteArticleById(id);
        return Result.success();
=======
public class ArticleController {

    @GetMapping("/list")
    public Result<String> list(/**@RequestHeader(name = "Authorization") String token, HttpServletResponse response**/){
//        if (token == null){
//            return Result.error("令牌为空");
//        }
//        try {
//            Map<String, Object> map = JwtUtil.parseToken(token);
//            return Result.success("文章列表...");
//        }catch (Exception e){
//            //set 404
//            response.setStatus(401);
//            return Result.error("未登录");
//        }
        //添加过滤器统一过滤
        return Result.success("文章列表...");

>>>>>>> 08ea7c3a718b4abad24581cc274164043dc145f5

    }

}
